window.jq_oldajax = $.ajax;
(function () {
  window.szoa = {
    client: {
      url: "http://szoa.com:99/",
      domain: "szoa.com:99",
      module: "backend",
      path: "/pc",
      appid: "kl59kCsdJ3bEUd5Alm",
      appSecret: "Qraav8KxvpGlbZuu4KSLC3OWgxRe4eJJ",
      expires: 86400,
      tokenKey: "Kg-Token",
      userinfoKey: "User-Info",
      websocketUrl: "ws://szoa.com:22336/",
      uploadUrl: "backend/files/upfiles",
      idcSrc: "/static/video/message.mp3"
    },
    setCache: function (b, a, d) {
      d = void 0 === d ? 0 : d;
      try {
        var c = { data: a, time: Date.now() / 1e3, expire: d };
        a = JSON.stringify(c);
        window.localStorage.setItem(b, a);
      } catch (e) {
        console.log("bbq");
      }
    },
    getCache: function (b) {
      try {
        var a = window.localStorage.getItem(b),
          d = Date.now() / 1e3;
        return a
          ? ((a = JSON.parse(a)),
            a.expire && d - a.time > a.expire
              ? (window.localStorage.removeItem(b), !1)
              : a.data)
          : !1;
      } catch (c) {
        return !1;
      }
    },
    delCache: function (b) {
      try {
        window.localStorage.removeItem(b);
      } catch (a) {}
    },
    getEncrypt: function (b, a) {
      var d = [],
        c = [],
        e;
      for (e in b) "object" !== typeof b[e] && "signature" !== e && c.push(e);
      c.sort();
      for (e in c) d[c[e]] = b[c[e]];
      b = Qs.stringify(d);
      b = CryptoJS.SHA1(b).toString(CryptoJS.enc.Hex);
      return CryptoJS.MD5(b + a).toString(CryptoJS.enc.Hex);
    },
    getToken: function () {
      return this.getCache(this.client.tokenKey);
    },
    setToken: function (b) {
      return this.setCache(this.client.tokenKey, b, this.client.expires);
    },
    removeToken: function () {
      return this.delCache(this.client.tokenKey);
    },
    getSignature: function (b) {
      var a = {};
      b && (a = b);
      b = this.getEncrypt(a, this.client.appSecret);
      a.signature = b;
      return a;
    },
    replaceSpace: function (b) {
      return b.split(" ").join("%20");
    },
    signeditdata: function (b) {
      b = b || {};
      b = JSON.parse(JSON.stringify(b));
      var a = Object.keys(b),
        d = {},
        c = 0,
        e;
      for (e in b) {
        if ("object" === typeof b[e] && null !== b[e]) {
          var g = a[c],
            f = 0,
            h;
          for (h in b[e]) (d[g + "_" + f] = b[e][h]), f++;
          d[g] = f;
        } else d[a[c]] = b[e];
        c++;
      }
      return d;
    },
    encode: function (b) {
      if ("object" === typeof b)
        for (var a in b)
          if (
            ("string" === typeof b[a] && (b[a] = encodeURIComponent(b[a])),
            "object" === typeof b[a])
          )
            for (var d in b[a])
              "string" === typeof b[a][d] &&
                (b[a][d] = encodeURIComponent(b[a][d]));
      return b;
    },
    ajax: function (b, a) {
      "object" === typeof b ? ((a = b), (b = void 0)) : (a.url = b || a.url);
      b = {
        url: szoa.client.url + szoa.client.module + (a.url ? a.url : ""),
        data: a.data || {},
        dataType: a.dataType || "json",
        type: a.type || "GET",
        success: function (c) {
          c &&
            c.code &&
            2101 == c.code &&
            (window.location.href = szoa.client.path + "/pages/login.html");
          c &&
            c.code &&
            2103 == c.code &&
            (window.location.href = szoa.client.path + "/pages/other.html");
          "function" === typeof a.success && a.success(c);
        },
        timeout: a.timeout || 3e5,
        error: function (c, e) {
          "function" === typeof a.error && a.error(c, e);
        },
        complete: function () {
          "function" === typeof a.complete && a.complete();
        },
        beforeSend: function (c) {
          c.setRequestHeader("Kg-Appid", szoa.client.appid);
          c.setRequestHeader("Kg-Token", szoa.getToken());
          "function" === typeof a.beforeSend && a.beforeSend(c);
        }
      };
      void 0 !== a.selfurl && (b.url = a.selfurl);
      void 0 !== a.processData && (b.processData = a.processData);
      void 0 !== a.contentType && (b.contentType = a.contentType);
      void 0 !== a.global && (b.global = a.global);
      void 0 !== a.ifModified && (b.ifModified = a.ifModified);
      void 0 !== a.cache && (b.cache = a.cache);
      void 0 !== a.async && (b.async = a.async);
      void 0 !== a.xhr && (b.xhr = a.xhr);
      void 0 !== a.context && (b.context = a.context);
      void 0 !== a.dataFilter && (b.dataFilter = a.dataFilter);
      void 0 !== a.jsonp &&
        void 0 !== a.jsonpCallback &&
        ((b.jsonp = a.jsonp), (b.jsonpCallback = a.jsonpCallback));
      void 0 !== a.username &&
        void 0 !== a.password &&
        ((b.username = a.username), (b.password = a.password));
      void 0 !== a.scriptCharset && (b.scriptCharset = a.scriptCharset);
      void 0 !== a.traditional && (b.traditional = a.traditional);
      void 0 !== a.headers && (b.headers = a.headers);
      b.type && (b.type = b.type.toUpperCase());
      void 0 !== b.xhr && (a.sign = 1);
      void 0 !== a.encode && 1 === a.encode && (b.data = szoa.encode(b.data));
      if (void 0 === a.sign || 1 !== a.sign)
        if ("POST" === b.type) {
          var d = null;
          d = 1 === a.dataHaveArray ? szoa.signeditdata(b.data) : b.data;
          b.data = szoa.getSignature(d);
          b.data = Qs.stringify(b.data);
        } else "GET" === b.type && (b.data = szoa.getSignature(b.data));
      jq_oldajax(b);
    },
    get: function (b, a, d) {
      var c = {};
      if ("object" === typeof a) (c = a), (callback = d);
      else if ("function" === typeof a) (c = {}), (callback = a);
      else return !1;
      szoa.ajax({
        url: b,
        data: c,
        type: "GET",
        success: function (e) {
          "function" === typeof callback && callback(e);
        }
      });
    },
    post: function (b, a, d) {
      szoa.ajax({
        url: b,
        data: a,
        type: "POST",
        success: function (c) {
          "function" === typeof d && d(c);
        }
      });
    }
  };
})();
$.ajax = szoa.ajax;
$.get = szoa.get;
$.post = szoa.post;
